//
//  WoDeDingDanViewController.m
//  XiangMu
//
//  Created by 康世标 on 15/8/12.
//  Copyright (c) 2015年 康世标. All rights reserved.
//
#define SCROLLVIEW_X _scrollView.frame.origin.x
#define SCROLLVIEW_Y _scrollView.frame.origin.y
#define SCROLLVIEW_WIDTH _scrollView.frame.size.width
#define SCROLLVIEW_HEIGHT _scrollView.frame.size.height

#import "WoDeDingDanViewController.h"

@interface WoDeDingDanViewController ()

@end

@implementation WoDeDingDanViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tabBarController.tabBar.hidden=YES;
    
    UIButton *fanHuiBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    fanHuiBtn.frame=CGRectMake(20, 20, 10, 20);
    
    [fanHuiBtn setBackgroundImage:[UIImage imageNamed:@"fanhui"] forState:UIControlStateNormal];
    
    [fanHuiBtn addTarget:self action:@selector(FanHui) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *barFanHui=[[UIBarButtonItem alloc]initWithCustomView:fanHuiBtn];
    self.navigationItem.leftBarButtonItem=barFanHui;

    
//    _bjView.layer.borderWidth=.3;
    _hongView=[[UIView alloc]initWithFrame:CGRectMake(10, 37, 80, 2)];
    _hongView.backgroundColor=[UIColor redColor];
    [_bjView addSubview:_hongView];
    
    _scrollView.contentSize=CGSizeMake(kScreenW*3, 0);
    _scrollView.contentOffset=CGPointMake(0, 0);
    _scrollView.pagingEnabled=YES;
    _scrollView.delegate=self;
    q=[[QuanBuViewController alloc]init];
    q.view.frame=CGRectMake(SCROLLVIEW_X, SCROLLVIEW_Y-40, SCROLLVIEW_WIDTH, SCROLLVIEW_HEIGHT);
    
    [_scrollView addSubview:q.view];
    [self addChildViewController:q];
   
   j=[[JinXingZhongViewController alloc]init];
    
    j.view.frame=CGRectMake(SCROLLVIEW_X+kScreenW, SCROLLVIEW_Y-40, SCROLLVIEW_WIDTH, SCROLLVIEW_HEIGHT);
    [_scrollView addSubview:j.view];
    
    [self addChildViewController:j];

    w =[[WanChengViewController alloc]init];
    w.view.frame=CGRectMake(SCROLLVIEW_X+(2*kScreenW), SCROLLVIEW_Y-40, SCROLLVIEW_WIDTH, SCROLLVIEW_HEIGHT);
    [_scrollView addSubview:w.view];
    [self addChildViewController:w];
    
  [_quanBuBtn setTitleColor:CL_00cc85 forState:UIControlStateSelected];
  [_quanBuBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    [_JinXingBtn setTitleColor:CL_00cc85 forState:UIControlStateSelected];
    [_JinXingBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_wanChengBtn setTitleColor:CL_00cc85 forState:UIControlStateSelected];
    [_wanChengBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    // Do any additional setup after loading the view from its nib.
   _quanBuBtn.selected=YES;
}
- (IBAction)WoDe:(id)sender {
    
    [UIView animateWithDuration:.5 animations:^{
        CGPoint point =_quanBuBtn.center;
        point.y=point.y+18.0f;
        _hongView.center=point;
    }];
    [_scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
    
    _quanBuBtn.selected = YES;
    _JinXingBtn.selected = NO;
    _wanChengBtn.selected = NO;
    
}
- (IBAction)JinXingZhong:(id)sender {
    
    [UIView animateWithDuration:.5 animations:^{
        CGPoint point =_JinXingBtn.center;
        point.y=point.y+18.0f;
        _hongView.center = point;

    }];
    [_scrollView setContentOffset:CGPointMake(kScreenW, 0) animated:YES];
    _quanBuBtn.selected=NO;
    _JinXingBtn.selected=YES;
    _wanChengBtn.selected=NO;
}
- (IBAction)YiWanCheng:(id)sender {
    [UIView animateWithDuration:.5 animations:^{
        CGPoint point =_wanChengBtn.center;
        point.y =point.y+18.0f;
        _hongView.center =point;
    }];
     [_scrollView setContentOffset:CGPointMake(kScreenW*2, 0) animated:YES];
    _quanBuBtn.selected=NO;
    _JinXingBtn.selected=NO;
    _wanChengBtn.selected=YES;
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    
     int oce=scrollView.contentOffset.x/_scrollView.frame.size.width;
  
    switch (oce ) {
        case 0:
        {
            [UIView animateWithDuration:.5 animations:^{
                CGPoint point =_quanBuBtn.center;
                point.y=point.y+18.0f;
                _hongView.center=point;
            }];
            
            _quanBuBtn.selected=YES;
            _wanChengBtn.selected=NO;
            _JinXingBtn.selected=NO;
            
        }
            break;
        case 1:
        {
            
            [UIView animateWithDuration:.5 animations:^{
                CGPoint point =_JinXingBtn.center;
                point.y=point.y+18.0f;
                _hongView.center=point;
                
            }];
            _JinXingBtn.selected=YES;
            _quanBuBtn.selected=NO;
            _wanChengBtn.selected=NO;
        }
            break;
        case 2:
        {
            [UIView animateWithDuration:.5 animations:^{
                CGPoint point =_wanChengBtn.center;
                point.y=point.y+18.0f;
                _hongView.center=point;
                
            }];
            _JinXingBtn.selected=NO;
            _quanBuBtn.selected=NO;
            _wanChengBtn.selected=YES;
        }
            break;
 
        default:
            break;
    }
    
}
-(void)FanHui{
     self.tabBarController.tabBar.hidden=NO;
    [self.navigationController popViewControllerAnimated:YES];
   
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
